/**
 * 
 */
package recognition.preprocessor;

import handwritten.gesture.MultiGesture;

import java.util.ArrayList;
import java.util.Hashtable;

import recognition.input.Input;

/**
 * @author tioz
 *
 */
public abstract class Preprocessor {
	
	
	private ArrayList<Input<?>> dependentInputs = new ArrayList<Input<?>>();
	private ArrayList<Preprocessor> childs = new ArrayList<Preprocessor>();
	/**
	 * 
	 */
	protected abstract boolean preprocess(MultiGesture gest);
	
	@SuppressWarnings("unchecked")
	public boolean preprocess(MultiGesture gest, Hashtable<Class<? extends Input<?>>,Input<?>> inputs){
		
		System.out.println(this.getClass().getCanonicalName());
		
		boolean ok = preprocess(gest);
		//gest.paintInNewFrame(this.getClass().getCanonicalName());
		
		if(ok){
			for(Input<?> i : dependentInputs)
				inputs.put((Class<? extends Input<?>>) i.getClass(), i.createInput(gest));
			
			for(Preprocessor p : childs)
			{
				p.preprocess( (MultiGesture) gest.clone(), inputs);
			}
		}
		
		return ok;
	}
	
	
	public void addDependentInput(Input<?> i){
		dependentInputs.add(i);
	}
	
	public void addChild(Preprocessor p){
		childs.add(p);
	}
	
	public void reset(){
		
	}
	
}
